/****************************************************************************
**
****************************************************************************/

#include "formMainWindow.h"
#include "ui_formMainWindow.h"

#include <QTimer>
#include <QDateTime>
#include <QSettings>

#include "formPassword.h"

#include "util.h"
#include "hciMain.h"
#include "cardMain.h"
#include "chargeMain.h"
#include "oiovMain.h"
#include "oiovCallback.h"
#include "baseUpdate.h"
#include "recordMain.h"
#include "iotUpgradeMain.h"

#include <QDebug>
#define MAIN_DEBUG

FormMainWindow::FormMainWindow(QWidget *parent) : QMainWindow(parent),
    ui(new Ui::FormMainWindow)
{
    ui->setupUi(this);

    qDebug() << "-------------------------------------------------------------------------------------------------------------";
    qDebug() << "---------------------------------------------- Version:" << TCU_SOFTWARE << "----------------------------------------------";
    qDebug() << "-------------------------------------------------------------------------------------------------------------";

    qRegisterMetaType<BaseUIData>("BaseUIData");

    ui->StackedWidget->setCurrentIndex(0);
    ui->CPChargingInfotabWidget->setCurrentIndex(0);
    ui->ConfigPageTabWidget->setCurrentIndex(6);
    ui->BaseConfigTabWidget->setCurrentIndex(0);
    ui->SystemConfigTabWidget->setCurrentIndex(0);
    ui->SystemCheckSelfTabWidget->setCurrentIndex(0);
    ui->RecordConfigTabWidget->setCurrentIndex(1);

    ui->CPModelLineEdit->setEnabled(true);
    ui->CPVendorLineEdit->setEnabled(true);
    ui->QRPrefixLineEdit->setEnabled(true);
    ui->QRPostfixLineEdit->setEnabled(true);
    ui->NetAddrLineEdit->setEnabled(true);
    ui->NetPortLineEdit->setEnabled(true);
    ui->NetTypeComboBox->setEnabled(false);
    ui->NetTypeComboBox->setCurrentIndex(0); //index: 0 --> Text: 4G
    if ("4G" == ui->NetTypeComboBox->currentText()) {
        ui->EthNetAddrLineEdit->setEnabled(false);
    } else {
        ui->EthNetAddrLineEdit->setEnabled(true);
    }
    ui->NetProocolComboBox->setEnabled(false);
    switch (IOV_PROTOCOL_TYPE) {
    case KIovProtolTypeTaixiangchong:
        ui->NetProocolComboBox->setCurrentIndex(0); //index: 0 --> Taixiangchong, 1 --> Yunkuaichong, 2 --> OCPP
        break;
    case KIovProtolTypeYunkuaichong:
        ui->NetProocolComboBox->setCurrentIndex(1); //index: 0 --> Taixiangchong, 1 --> Yunkuaichong, 2 --> OCPP
        break;
    case KIovProtolTypeOCPP:
        ui->NetProocolComboBox->setCurrentIndex(2); //index: 0 --> Taixiangchong, 1 --> Yunkuaichong, 2 --> OCPP
        break;
    default:
        break;
    }
    ui->CardReaderTypeComboBox->setEnabled(false);
    ui->CardReaderTypeComboBox->setCurrentIndex(1); //index: 0 --> Puyue, 1 --> ZLG, 2 --> None

    ui->OnlineCardTypeComboBox->setEnabled(false);
    switch (IOV_PROTOCOL_TYPE) {
    case KIovProtolTypeTaixiangchong:
        ui->OnlineCardTypeComboBox->setCurrentIndex(0); //index: 0 --> Taixiangchong, 1 --> Yunkuaichong, 2 --> None
        break;
    case KIovProtolTypeYunkuaichong:
        ui->OnlineCardTypeComboBox->setCurrentIndex(1); //index: 0 --> Taixiangchong, 1 --> Yunkuaichong, 2 --> None
        break;
    case KIovProtolTypeOCPP:
        ui->OnlineCardTypeComboBox->setCurrentIndex(2); //index: 0 --> Taixiangchong, 1 --> Yunkuaichong, 2 --> None
        break;
    default:
        break;
    }
    ui->OfflineCardTypeComboBox->setEnabled(false);
    ui->OfflineCardTypeComboBox->setCurrentIndex(0); //index: 0 --> Taixiangchong
    ui->OfflineCardRuleComboBox->setEnabled(false);
    ui->OfflineCardRuleComboBox->setCurrentIndex(0); //index: 0 --> 卡号与桩编码完全一致

    ui->OfflineChargingPB->setEnabled(true);
    ui->LocalCardChargingPB->setEnabled(false);
    ui->OnlineVinChargingPB->setEnabled(false);

    ui->SysConfigWritePB->setEnabled(true);
    ui->SysConfigReadPB->setEnabled(false);
    ui->ModelTypeComboBox->setEnabled(true);
    ui->ModelANumbLineEdit->setEnabled(true);
    ui->ModelBNumbLineEdit->setEnabled(true);
    ui->MeterComboBox->setEnabled(true);
    ui->LockTypeComboBox->setEnabled(true);
    ui->LockFBComboBox->setEnabled(true);

    ui->A24VolPB->setEnabled(true);
    ui->B24VolPB->setEnabled(true);
    ui->APowerCtrLineEdit->setEnabled(true);
    ui->BPowerCtrLineEdit->setEnabled(true);
    QIntValidator *IntValidator = new QIntValidator(this);
    IntValidator->setRange(1, 120);
    ui->APowerCtrLineEdit->setValidator(IntValidator);
    ui->BPowerCtrLineEdit->setValidator(IntValidator);

    ui->AForcedChargingPB->setEnabled(true);
    ui->BForcedChargingPB->setEnabled(true);
    ui->SystemCheckSelfPB->setEnabled(true);

    ui->STCUVerLabel->setEnabled(false);
    ui->SCCUVerLabel->setEnabled(false);
    ui->LocalUpdateTextEdit->setText("");
    ui->LocalUpdateTextEdit->setText("1. 将升级文件命名为 'tcu' \r\n"
                                     "2. 在 U 盘根目录新建文件夹 'tcu_update' \r\n"
                                     "3. 将 'tcu' 文件放入 'tcu_update' 文件夹中 \r\n"
                                     "4. 将 U 盘插入 TCU 中，执行 <前置检测> --> <本地升级> \r\n"
                                     "--------------------------------------------------------------- \r\n");

    dummyTimer = new QTimer();
    dummyTimer->setInterval(10);
    dummyTimer->setTimerType(Qt::CoarseTimer);
    dummyTimer->start();

    formPassword_ = new FormPassword(this);

    orderRecord_ = new RecordMain(); //...
    /*
    orderrecord_->start(); */

    chargeMainList_.append(new ChargeMain(CONGUNNOA));
    chargeMainList_.append(new ChargeMain(CONGUNNOB));
    for (int i = 0; i < chargeMainList_.size(); i++) {
        chargeMainList_.at(i)->start();
    }

    hciMain_ = new HciMain(&chargeMainList_);
    hciMain_->start();

    cardMain_ = new CardMain(&chargeMainList_, hciMain_);
    cardMain_->start();

    baseUpdate_ = new BaseUpdate();
    oiovCallback_ = new OiovCallback();

    oiovResMain_ = new OiovResMain();
    oiovResMain_->start();
    oiovReqMain_ = new OiovReqMain();
    oiovReqMain_->start();

    iotUpgrade_ = new IotUpgrade(&chargeMainList_);
    iotUpgrade_->start();

    controllerParserMain_.start();
    controllerRecvMain_.start();
    controllerSendMain_.start();

    connect(formPassword_, &FormPassword::CheckSuccess, hciMain_, &HciMain::ShowConfigPage);

    connect(ui->HPConfigPB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->OfflineChargingPB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->LocalCardChargingPB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->OnlineVinChargingPB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->SysConfigWritePB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->SysConfigReadPB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->A24VolPB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->B24VolPB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->AForcedChargingPB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->BForcedChargingPB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->SystemCheckSelfPB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->RecordUpPagePB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->RecordNextPagePB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->GPEnterPB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);
    connect(ui->GPCancelPB, &QPushButton::clicked, this, &FormMainWindow::HandleButton);

    connect(ui->HPQRAPushButton, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->HPQRBPushButton, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->HPCardAPB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->HPCardBPB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->HPVinAPB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->HPVinBPB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->DPReturnHomePB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->CPStopPB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->CPReturnHomePB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->FPReturnHomePB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->TPReturnHomePB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->LocalUpdatePrePB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->LocalUpdatePB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->DPStartPB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);
    connect(ui->CPStopPB, &QPushButton::clicked, hciMain_, &HciMain::HandleButton);

    connect(hciMain_, &HciMain::ChangePage, this, &FormMainWindow::ChangePage);
    connect(hciMain_, &HciMain::ShowSysConfigData, this, &FormMainWindow::ShowSysConfigData);
    connect(hciMain_, &HciMain::ShowSysCheckData, this, &FormMainWindow::ShowSysCheckData);
    connect(hciMain_, &HciMain::UpdateData, this, &FormMainWindow::UpdateData);
    connect(hciMain_, &HciMain::UpdateDateTime, this, &FormMainWindow::UpdateDateTime);

    connect(oiovReqMain_, &OiovReqMain::StartUpdate, baseUpdate_, &BaseUpdate::StartDownloadFile);
    connect(baseUpdate_, &BaseUpdate::DownloadFinish, &controllerSendMain_, &ControllerSendMain::StartUpdate);

    ui->HPQRAPushButton->setStyleSheet("border-image: url(./qrcodeA.png);");
    ui->HPQRBPushButton->setStyleSheet("border-image: url(./qrcodeB.png);");

    ui->OfflineChargingPB->setText(BaseConfigure::offline_hci_charge() ? tr("禁用") : tr("启用"));
    ui->A24VolPB->setText(BaseConfigure::apu24(kGunNumberA) ? tr("禁用") : tr("启用"));
    ui->B24VolPB->setText(BaseConfigure::apu24(kGunNumberB) ? tr("禁用") : tr("启用"));

    if (tr("启用") == ui->A24VolPB->text()) {
        ui->HPTextALabel->setText(tr("A 枪 (12V)"));
    } else {
        ui->HPTextALabel->setText(tr("A 枪 (24V)"));
    }
    if (tr("启用") == ui->B24VolPB->text()) {
        ui->HPTextBLabel->setText(tr("B 枪 (12V)"));
    } else {
        ui->HPTextBLabel->setText(tr("B 枪 (24V)"));
    }

    if (tr("启用") == ui->OfflineChargingPB->text()) {
        ui->DPStartPB->setVisible(false);
        ui->CPStopPB->setVisible(false);
    } else {
        ui->DPStartPB->setVisible(true);
        ui->CPStopPB->setVisible(true);
    }
}

FormMainWindow::~FormMainWindow()
{
    if (nullptr != oiovReqMain_) {
        delete oiovReqMain_;
        oiovReqMain_ = nullptr;
    }

    if (nullptr != oiovResMain_) {
        delete oiovResMain_;
        oiovResMain_ = nullptr;
    }

    if (nullptr != oiovCallback_) {
        delete oiovCallback_;
        oiovCallback_ = nullptr;
    }

    if (nullptr != baseUpdate_) {
        delete baseUpdate_;
        baseUpdate_ = nullptr;
    }

    if (nullptr != hciMain_) {
        delete hciMain_;
        hciMain_ = nullptr;
    }

    if (nullptr != dummyTimer) {
        delete dummyTimer;
        dummyTimer = nullptr;
    }

    if (nullptr != formPassword_) {
        formPassword_->close();
        delete formPassword_;
        formPassword_ = nullptr;
    }

    delete ui;
}

void FormMainWindow::ChangePage(const quint8& index)
{
    ui->StackedWidget->setCurrentIndex(index);
}

void FormMainWindow::ShowSysConfigData(const BaseUIData& data)
{
    ui->SystemConfigLabel->setText(data.sys_config_info());
}

void FormMainWindow::ShowSysCheckData(const BaseUIData& data)
{
    unsigned char version;
    int page_index = ui->StackedWidget->currentIndex();

    switch (page_index) {
    case HciMain::kHomePage:
        break;
    case HciMain::kCardPage:
        break;
    case HciMain::kStartOrStopPage:
        break;
    case HciMain::kFaultPage:
        break;
    case HciMain::kChargingPage:
        break;
    case HciMain::kFinishPage:
        break;
    case HciMain::kConfigPage:
        ui->SystemCheckSelfTab1LineEdit1->setText(data.gun_main_positive_relay(kGunNumberA) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab1LineEdit2->setText(data.gun_main_negative_relay(kGunNumberA) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab1LineEdit3->setText(data.aps_positive_relay(kGunNumberA) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab1LineEdit4->setText(data.aps_negative_relay(kGunNumberA) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab1LineEdit5->setText(data.electronic_lock(kGunNumberA) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab1LineEdit6->setText(data.gun_main_positive_relay(kGunNumberB) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab1LineEdit7->setText(data.gun_main_negative_relay(kGunNumberB) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab1LineEdit8->setText(data.aps_positive_relay(kGunNumberB) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab1LineEdit9->setText(data.aps_negative_relay(kGunNumberB) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab1LineEdit10->setText(data.electronic_lock(kGunNumberB) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab2LineEdit1->setText(data.gun_head_temp_feedback(kGunNumberA) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab2LineEdit2->setText(data.meter_feedback(kGunNumberA) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab2LineEdit3->setText(data.gun_can_feedback(kGunNumberA) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab2LineEdit4->setText(data.fan_feedback(kGunNumberA) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab2LineEdit6->setText(data.gun_head_temp_feedback(kGunNumberB) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab2LineEdit7->setText(data.meter_feedback(kGunNumberB) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab2LineEdit8->setText(data.gun_can_feedback(kGunNumberB) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab2LineEdit9->setText(data.fan_feedback(kGunNumberB) ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab3LineEdit1->setText(data.contactor_relay() ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab3LineEdit2->setText(data.model_parallel_main_positive_relay() ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab3LineEdit3->setText(data.model_parallel_main_negative_relay() ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab3LineEdit4->setText(data.model_can_feedback() ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab3LineEdit6->setText(data.estop_feedback() ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab3LineEdit7->setText(data.access_control_feedback() ? "< N >" : "< Y >");
        ui->SystemCheckSelfTab3LineEdit8->setText("< / >");
        ui->SystemCheckSelfTab3LineEdit9->setText(data.card_feedback() ? "< N >" : "< Y >");
        ui->STCUVerLabel->setText("v" + QString::number(BaseUpdate::version()) + "." + QString::number(BaseUpdate::subversion()) + "." + QString::number(BaseUpdate::revision()) + " - " + QString(EVDC_VERSION));
        version = ControllerParserMain::con_feedback_version_check[0].sccu_ver;
        ui->SCCUVerLabel->setText("v" + QString::number((version >> 4) & 0x0F) + "." + QString::number(version & 0x0F));
        break;
    case HciMain::kUpdatePage:
        break;
    default:
        break;
    }
}

void FormMainWindow::UpdateData(const BaseUIData& data)
{
    static quint8 gif_index = 0;

    int page_index;
    QString string = 0;
    quint32 number = 0;

    page_index = ui->StackedWidget->currentIndex();
    switch (page_index) {
    case HciMain::kHomePage:
        ui->HPInfoLabel->setText("");
        ui->HPTextALabel->setText(data.text_home(kGunNumberA));
        ui->HPQRAPushButton->setStyleSheet(data.qrcode_home(kGunNumberA));
        ui->HPCardAPB->setText(data.state_home(kGunNumberA));
        ui->HPTextBLabel->setText(data.text_home(kGunNumberB));
        ui->HPQRBPushButton->setStyleSheet(data.qrcode_home(kGunNumberB));
        ui->HPCardBPB->setText(data.state_home(kGunNumberB));
        if (data.net_state()) {
            ui->HPNetLabel->setStyleSheet("border-image: url(:/img/img/anyo_network.png);");
        } else {
            ui->HPNetLabel->setStyleSheet("border-image: url(:/img/img/anyo_internet.png);");
        }
        break;
    case HciMain::kCardPage:
        ui->DPQRLabel->setStyleSheet(data.qrcode_card());
        ui->DPInfoLabel->setText(data.info_card());
        ui->DPSNLabel->setText(data.sn_card());
        ui->DPCardInfoLabel->setText("");
        break;
    case HciMain::kStartOrStopPage:
        ui->SSPInfoLabel->setText(data.info_identify());
        ui->SSPTimeoutLabel->setText(data.timeout_identify());
        break;
    case HciMain::kFaultPage:
        ui->TPImagesLabel->setStyleSheet("border-image: url(:/img/img/anyo_warning.jpg);");
        ui->TPInfoLabel->setText(data.info_warning());
        break;
    case HciMain::kChargingPage:
        ui->CPSNLabel->setText(data.sn_charging());
        string = QString::number(data.soc_charging()) + " %";
        ui->CPSocLabel->setText(string);
        if (data.cur_charging() > 0) {
            string = QString::number(data.cur_charging() * 0.1, 'f', 1) + " A";
        } else {
            string = QString::number(data.cur_charging() * 0.1) + " A";
        }
        ui->CPCurLabel->setText(string);
        if (data.vol_charging() > 0) {
            string = QString::number(data.vol_charging() * 0.1, 'f', 1) + " V";
        } else {
            string = QString::number(data.vol_charging() * 0.1) + " V";
        }
        ui->CPVolLabel->setText(string);
        if (data.elect_charging() > 0) {
            string = QString::number(data.elect_charging() * 0.01, 'f', 2) + " kW.h";
        } else {
            string = QString::number(data.elect_charging() * 0.01) + " kW.h";
        }
        ui->CPElectLabel->setText(string);
        number = data.time_charging();
        string = QString::number(number / 3600).sprintf("%02d", number / 3600) + " : " +
                 QString::number(number % 3600 / 60).sprintf("%02d", number % 3600 / 60) + " : " +
                 QString::number(number % 60).sprintf("%02d", number % 60);
        ui->CPChargeTimeLabel->setText(string);
        string = QString::number(data.max_temp()) + " ℃";
        ui->CPMaxTempLabel->setText(string);
        if (data.max_vol() > 0) {
            string = QString::number(data.max_vol() * 0.01, 'f', 2) + " V";
        } else {
            string = QString::number(data.max_vol() * 0.01) + " V";
        }
        ui->CPMaxVolLabel->setText(string);
        if (data.demand_cur() > 0) {
            string = QString::number(data.demand_cur() * 0.1, 'f', 1) + " A";
        } else {
            string = QString::number(data.demand_cur() * 0.1) + " A";
        }
        ui->CPDemandCUrLabel->setText(string);
        if (data.demand_vol() > 0) {
            string = QString::number(data.demand_vol() * 0.1, 'f', 1) + " V";
        } else {
            string = QString::number(data.demand_vol() * 0.1) + " V";
        }
        ui->CPDemandVolLabel->setText(string);
        switch (gif_index++) {
        case 0:
            ui->CPImagesLabel->setPixmap(QPixmap(":/img/img/anyo_charging_IMG00000.png"));
            break;
        case 1:
            ui->CPImagesLabel->setPixmap(QPixmap(":/img/img/anyo_charging_IMG00008.png"));
            break;
        case 2:
            ui->CPImagesLabel->setPixmap(QPixmap(":/img/img/anyo_charging_IMG00013.png"));
            break;
        case 3:
            ui->CPImagesLabel->setPixmap(QPixmap(":/img/img/anyo_charging_IMG00021.png"));
            break;
        case 4:
            ui->CPImagesLabel->setPixmap(QPixmap(":/img/img/anyo_charging_IMG00026.png"));
            break;
        case 5:
            ui->CPImagesLabel->setPixmap(QPixmap(":/img/img/anyo_charging_IMG00034.png"));
            break;
        case 6:
            ui->CPImagesLabel->setPixmap(QPixmap(":/img/img/anyo_charging_IMG00039.png"));
            break;
        case 7:
            ui->CPImagesLabel->setPixmap(QPixmap(":/img/img/anyo_charging_IMG00047.png"));
            break;
        case 8:
            ui->CPImagesLabel->setPixmap(QPixmap(":/img/img/anyo_charging_IMG00052.png"));
            break;
        case 9:
            ui->CPImagesLabel->setPixmap(QPixmap(":/img/img/anyo_charging_IMG00060.png"));
            break;
        default:
            gif_index = 0;
            break;
        }
        break;
    case HciMain::kFinishPage:
        ui->FPSNLable->setText(data.sn_chargend());
        string = QString::number(data.soc_chargend()) + " %";
        ui->FPSocLable->setText(string);
        if (data.elect_chargend() > 0) {
            string = QString::number(data.elect_chargend() * 0.01, 'f', 2) + " kW.h";
        } else {
            string = QString::number(data.elect_chargend() * 0.01) + " kW.h";
        }
        ui->FPElectLable->setText(string);
        number = data.time_chargend();
        string = QString::number(number / 3600).sprintf("%02d", number / 3600) + " : " +
                 QString::number(number % 3600 / 60).sprintf("%02d", number % 3600 / 60) + " : " +
                 QString::number(number % 60).sprintf("%02d", number % 60);
        ui->FPChargeTimeLabel->setText(string);
        ui->FPResultLabel->setText(data.result_chargend());
        break;
    case HciMain::kConfigPage:
        ui->CPModelLineEdit->setText(BaseConfigure::pile_model());
        ui->CPVendorLineEdit->setText(BaseConfigure::pile_vendor());
        ui->QRPrefixLineEdit->setText(BaseConfigure::qrcode_prefix());
        ui->QRPostfixLineEdit->setText(BaseConfigure::qrcode_post());
        ui->NetAddrLineEdit->setText(BaseConfigure::net_ip());
        ui->NetPortLineEdit->setText(QString::number(BaseConfigure::net_port()));
        ui->NetTypeComboBox->setCurrentText(BaseConfigure::net_type());
        ui->ModelTypeComboBox->setCurrentText(BaseConfigure::model_type());
        ui->ModelANumbLineEdit->setText(QString::number(BaseConfigure::model_count(kGunNumberA)));
        ui->ModelBNumbLineEdit->setText(QString::number(BaseConfigure::model_count(kGunNumberB)));
        ui->MeterComboBox->setCurrentText(QString::number(BaseConfigure::meter_baud()));
        ui->LockTypeComboBox->setCurrentText(BaseConfigure::lock_type());
        ui->LockFBComboBox->setCurrentText(BaseConfigure::lock_fb());
        ui->APowerCtrLineEdit->setText(QString::number(BaseConfigure::power_ctrl(kGunNumberA)));
        ui->BPowerCtrLineEdit->setText(QString::number(BaseConfigure::power_ctrl(kGunNumberB)));
        ui->LocalUpdateTextEdit->setText("1. 将升级文件命名为 'tcu' \r\n"
                                         "2. 在 U 盘根目录新建文件夹 'tcu_update' \r\n"
                                         "3. 将 'tcu' 文件放入 'tcu_update' 文件夹中 \r\n"
                                         "4. 将 U 盘插入 TCU 中，执行 <前置检测> --> <本地升级> \r\n"
                                         "--------------------------------------------------------------- \r\n" + data.local_update_info());
        break;
    case HciMain::kUpdatePage:
        ui->UProgressBar->setValue(static_cast<int>(data.update_progress()));
        ui->UProgressBar->setFormat(QString::fromLocal8Bit("%1%").arg(QString::number(data.update_progress(), 'f', 2)));
        break;
    default:
        break;
    }
}

void FormMainWindow::UpdateDateTime()
{
    QString date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
    qint32 page_index = ui->StackedWidget->currentIndex();
    switch (page_index) {
    case HciMain::kHomePage:
        ui->HPTimeLabel->setText(date_time);
        break;
    case HciMain::kCardPage:
        break;
    case HciMain::kStartOrStopPage:
        break;
    case HciMain::kFaultPage:
        break;
    case HciMain::kChargingPage:
        ui->CPTimeLabel->setText(date_time);
        break;
    case HciMain::kFinishPage:
        ui->FPTimeLabel->setText(date_time);
        break;
    case HciMain::kConfigPage:
        break;
    case HciMain::kUpdatePage:
        ui->UPTimeLabel->setText(date_time);
        break;
    default:
        break;
    }
}

void FormMainWindow::HandleButton()
{
    QPushButton *obj = (QPushButton *)sender();
    QString button_name = obj->objectName();

#ifdef MAIN_DEBUG
    qDebug() << "[MAIN]-> active button:" << button_name;
#endif

    if ("HPConfigPB" == button_name) {
        if (formPassword_->isVisible()) {
            return;
        }
        formPassword_->ClearText();
        formPassword_->setWindowModality(Qt::NonModal);
        formPassword_->show();
    } else if ("OfflineChargingPB" == button_name) {
        if (tr("启用") == ui->OfflineChargingPB->text()) {
            ui->OfflineChargingPB->setText(tr("禁用"));
        } else {
            ui->OfflineChargingPB->setText(tr("启用"));
        }

        if (tr("启用") == ui->OfflineChargingPB->text()) {
            BaseConfigure::set_offline_hci_charge(false);

            ui->DPStartPB->setVisible(false);
            ui->CPStopPB->setVisible(false);
        } else {
            BaseConfigure::set_offline_hci_charge(true);

            ui->DPStartPB->setVisible(true);
            ui->CPStopPB->setVisible(true);
        }
    } else if ("LocalCardChargingPB" == button_name) {
        //...
    } else if ("OnlineVinChargingPB" == button_name) {
        //...
    } else if ("SysConfigWritePB" == button_name) {
        memset((void *) & (ControllerSendMain::con_sys_get_set[kGunNumberA]), 0xFF, sizeof(ControllerSendMain::con_sys_get_set[kGunNumberA]));
        ControllerSendMain::con_sys_get_set[kGunNumberA].gnu_no = CONGUNNOA;
        ControllerSendMain::con_sys_get_set[kGunNumberA].set_type = 0x01; //write system config
        if ("None" == ui->LockTypeComboBox->currentText()) {
            BaseConfigure::set_lock_type(tr("None"));
            ControllerSendMain::con_sys_get_set[kGunNumberA].lock_type = 0x03;
        } else {
            BaseConfigure::set_lock_type(tr("Pulse"));
            ControllerSendMain::con_sys_get_set[kGunNumberA].lock_type = 0x02;
        }
#ifdef MAIN_DEBUG
        qDebug() << "[MAIN]-> Write Config LockType:" << ui->LockTypeComboBox->currentText();
#endif
        if ("1200" == ui->MeterComboBox->currentText()) {
            BaseConfigure::set_meter_baud(1200);
            ControllerSendMain::con_sys_get_set[kGunNumberA].meter_baud = 0x01;
        } else if ("2400" == ui->MeterComboBox->currentText()) {
            BaseConfigure::set_meter_baud(2400);
            ControllerSendMain::con_sys_get_set[kGunNumberA].meter_baud = 0x02;
        } else if ("4800" == ui->MeterComboBox->currentText()) {
            BaseConfigure::set_meter_baud(4800);
            ControllerSendMain::con_sys_get_set[kGunNumberA].meter_baud = 0x03;
        } else if ("19200" == ui->MeterComboBox->currentText()) {
            BaseConfigure::set_meter_baud(19200);
            ControllerSendMain::con_sys_get_set[kGunNumberA].meter_baud = 0x05;
        } else if ("115200" == ui->MeterComboBox->currentText()) {
            BaseConfigure::set_meter_baud(115200);
            ControllerSendMain::con_sys_get_set[kGunNumberA].meter_baud = 0x06;
        } else {
            BaseConfigure::set_meter_baud(9600);
            ControllerSendMain::con_sys_get_set[kGunNumberA].meter_baud = 0x04;
        }
#ifdef MAIN_DEBUG
        qDebug() << "[MAIN]-> Write Config MeterBaud:" << ui->MeterComboBox->currentText();
#endif
        if ("Increase" == ui->ModelTypeComboBox->currentText()) {
            BaseConfigure::set_model_type("Increase");
            ControllerSendMain::con_sys_get_set[kGunNumberA].model_type = 0x04;
        } else if ("Huawei" == ui->ModelTypeComboBox->currentText()) {
            BaseConfigure::set_model_type("Huawei");
            ControllerSendMain::con_sys_get_set[kGunNumberA].model_type = 0x05;
        } else {
            BaseConfigure::set_model_type("Infy");
            ControllerSendMain::con_sys_get_set[kGunNumberA].model_type = 0x02;
        }
#ifdef MAIN_DEBUG
        qDebug() << "[MAIN]-> Write Config ModelType:" << ui->ModelTypeComboBox->currentText();
#endif
        if ("Normal Close" == ui->LockFBComboBox->currentText()) {
            BaseConfigure::set_lock_fb("Normal Close");
            ControllerSendMain::con_sys_get_set[kGunNumberA].lock_fb = 0x02;
        } else {
            BaseConfigure::set_lock_fb("Normal Open");
            ControllerSendMain::con_sys_get_set[kGunNumberA].lock_fb = 0x01;
        }
#ifdef MAIN_DEBUG
        qDebug() << "[MAIN]-> Write Config LockFB:" << ui->LockFBComboBox->currentText();
#endif
        if ("0" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 0);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x00;
        } else if ("1" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 1);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x01;
        } else if ("2" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 2);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x02;
        } else if ("3" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 3);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x03;
        } else if ("4" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 4);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x04;
        } else if ("5" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 5);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x05;
        } else if ("6" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 6);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x06;
        } else if ("7" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 7);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x07;
        } else if ("8" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 8);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x08;
        } else if ("9" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 9);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x09;
        } else if ("10" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 10);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x0A;
        } else if ("11" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 11);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x0B;
        } else if ("12" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 12);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x0C;
        } else if ("13" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 13);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x0D;
        } else if ("14" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 14);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x0E;
        } else if ("15" == ui->ModelANumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberA, 15);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x0F;
        } else {
            BaseConfigure::set_model_count(kGunNumberA, 3);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_a_model_num = 0x03;
        }
#ifdef MAIN_DEBUG
        qDebug() << "[MAIN]-> Write Config A.ModelCount:" << ui->ModelANumbLineEdit->text();
#endif
        if ("0" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 0);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x00;
        } else if ("1" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 1);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x01;
        } else if ("2" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 2);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x02;
        } else if ("3" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 3);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x03;
        } else if ("4" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 4);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x04;
        } else if ("5" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 5);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x05;
        } else if ("6" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 6);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x06;
        } else if ("7" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 7);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x07;
        } else if ("8" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 8);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x08;
        } else if ("9" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 9);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x09;
        } else if ("10" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 10);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x0A;
        } else if ("11" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 11);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x0B;
        } else if ("12" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 12);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x0C;
        } else if ("13" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 13);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x0D;
        } else if ("14" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 14);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x0E;
        } else if ("15" == ui->ModelBNumbLineEdit->text()) {
            BaseConfigure::set_model_count(kGunNumberB, 15);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x0F;
        } else {
            BaseConfigure::set_model_count(kGunNumberB, 3);
            ControllerSendMain::con_sys_get_set[kGunNumberA].gunno_b_model_num = 0x03;
        }
#ifdef MAIN_DEBUG
        qDebug() << "[MAIN]-> Write Config B.ModelCount:" << ui->ModelBNumbLineEdit->text();
#endif
        memset(&(ControllerParserMain::con_frame_info[CON_PDUFORMAT_FEEDBACK_SYS_GET_SET]), 0x00, sizeof(con_frame_info_t));
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_GET_SET].gunno = CONGUNNOA;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_GET_SET].cycle = 250;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_GET_SET].count = 0;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_GET_SET].timeout = 5000;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_GET_SET].time = ControllerSendMain::timestamp_ms();
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_GET_SET].pduformat = CON_PDUFORMAT_SYS_GET_SET;

        ui->SystemConfigLabel->setText(tr("正在等待写响应"));
    } else if ("SysConfigReadPB" == button_name) {
        memset((void *) & (ControllerSendMain::con_sys_get_set[kGunNumberA]), 0xFF, sizeof(ControllerSendMain::con_sys_get_set[kGunNumberA]));
        ControllerSendMain::con_sys_get_set[kGunNumberA].gnu_no = CONGUNNOA;
        ControllerSendMain::con_sys_get_set[kGunNumberA].set_type = 0x02; //read system config
        memset(&(ControllerParserMain::con_frame_info[CON_PDUFORMAT_FEEDBACK_SYS_GET_SET]), 0x00, sizeof(con_frame_info_t));
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_GET_SET].gunno = CONGUNNOA;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_GET_SET].cycle = 250;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_GET_SET].count = 0;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_GET_SET].timeout = 5000;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_GET_SET].time = ControllerSendMain::timestamp_ms();
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_GET_SET].pduformat = CON_PDUFORMAT_SYS_GET_SET;

        ui->SystemConfigLabel->setText(tr("正在等待读响应"));
    } else if ("A24VolPB" == button_name) {
        if (tr("启用") == ui->A24VolPB->text()) {
            ui->A24VolPB->setText("禁用");
        } else {
            ui->A24VolPB->setText("启用");
        }

        if (tr("启用") == ui->A24VolPB->text()) {
            BaseConfigure::set_apu24(kGunNumberA, false);
        } else {
            BaseConfigure::set_apu24(kGunNumberA, true);
        }
    } else if ("B24VolPB" == button_name) {
        if (tr("启用") == ui->B24VolPB->text()) {
            ui->B24VolPB->setText("禁用");
        } else {
            ui->B24VolPB->setText("启用");
        }

        if (tr("启用") == ui->B24VolPB->text()) {
            BaseConfigure::set_apu24(kGunNumberB, false);
        } else {
            BaseConfigure::set_apu24(kGunNumberB, true);
        }
    } else if ("AForcedChargingPB" == button_name) {
        memset(&(ControllerParserMain::con_feedback_startup_force[CON_PDUFORMAT_FEEDBACK_STARTUP_FORCE]), 0x00, sizeof(con_frame_info_t));
        if (tr("强制启动 ( A 枪 )") == ui->AForcedChargingPB->text()) {
            ui->AForcedChargingPB->setText(tr("强制停止 ( A 枪 )"));

            ControllerSendMain::con_startup_force[kGunNumberA].gnu_no = CONGUNNOA;
            ControllerSendMain::con_startup_force[kGunNumberA].cmd = 0x01; /* 0 - STOP, 1 - START */
            ControllerSendMain::con_startup_force[kGunNumberA].volt = 0x00;
            ControllerSendMain::con_startup_force[kGunNumberA].curr = 0x00;
        } else {
            ui->AForcedChargingPB->setText(tr("强制启动 ( A 枪 )"));

            ControllerSendMain::con_startup_force[kGunNumberA].gnu_no = CONGUNNOA;
            ControllerSendMain::con_startup_force[kGunNumberA].cmd = 0x00; /* 0 - STOP, 1 - START */
            ControllerSendMain::con_startup_force[kGunNumberA].volt = 0x00;
            ControllerSendMain::con_startup_force[kGunNumberA].curr = 0x00;
        }
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_STARTUP_FORCE].gunno = CONGUNNOA;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_STARTUP_FORCE].cycle = 250;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_STARTUP_FORCE].count = 0;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_STARTUP_FORCE].timeout = 5000;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_STARTUP_FORCE].time = ControllerSendMain::timestamp_ms();
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_STARTUP_FORCE].pduformat = CON_PDUFORMAT_STARTUP_FORCE;
    } else if ("BForcedChargingPB" == button_name) {
        memset(&(ControllerParserMain::con_feedback_startup_force[CON_PDUFORMAT_FEEDBACK_STARTUP_FORCE]), 0x00, sizeof(con_frame_info_t));
        if (tr("强制启动 ( B 枪 )") == ui->BForcedChargingPB->text()) {
            ui->BForcedChargingPB->setText(tr("强制停止 ( B 枪 )"));

            ControllerSendMain::con_startup_force[kGunNumberB].gnu_no = CONGUNNOB;
            ControllerSendMain::con_startup_force[kGunNumberB].cmd = 0x01; /* 0 - STOP, 1 - START */
            ControllerSendMain::con_startup_force[kGunNumberB].volt = 0x00;
            ControllerSendMain::con_startup_force[kGunNumberB].curr = 0x00;
        } else {
            ui->BForcedChargingPB->setText(tr("强制启动 ( B 枪 )"));

            ControllerSendMain::con_startup_force[kGunNumberB].gnu_no = CONGUNNOB;
            ControllerSendMain::con_startup_force[kGunNumberB].cmd = 0x00; /* 0 - STOP, 1 - START */
            ControllerSendMain::con_startup_force[kGunNumberB].volt = 0x00;
            ControllerSendMain::con_startup_force[kGunNumberB].curr = 0x00;
        }
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_STARTUP_FORCE].gunno = CONGUNNOB;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_STARTUP_FORCE].cycle = 250;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_STARTUP_FORCE].count = 0;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_STARTUP_FORCE].timeout = 5000;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_STARTUP_FORCE].time = ControllerSendMain::timestamp_ms();
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_STARTUP_FORCE].pduformat = CON_PDUFORMAT_STARTUP_FORCE;
    } else if ("SystemCheckSelfPB" == button_name) {
        memset((void *) & (ControllerParserMain::con_feedback_system_check), 0x00, sizeof(con_frame_info_t));
        ControllerSendMain::con_system_check.cmd = 0x01;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_CHECK].gunno = 0xFF;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_CHECK].cycle = 250;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_CHECK].count = 0;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_CHECK].timeout = 5000;
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_CHECK].time = ControllerSendMain::timestamp_ms();
        ControllerSendMain::con_frame_info[CON_PDUFORMAT_SYS_CHECK].pduformat = CON_PDUFORMAT_SYS_CHECK;
    } else if ("RecordUpPagePB" == button_name) {
        //...
    } else if ("RecordNextPagePB" == button_name) {
        //...
    } else if ("GPEnterPB" == button_name) {
        hciMain_->set_action_config(false);
        ChangePage(HciMain::kHomePage);

        switch (ui->ConfigPageTabWidget->currentIndex()) {
        case 0x00: //基础配置
            if (ui->CPVendorLineEdit->text() != BaseConfigure::pile_vendor()) {
                if (ui->CPVendorLineEdit->text().isEmpty()) {
                    return;
                }

                qDebug() << "[MAIN]-> Write Config charge Point Vendor:" << ui->CPVendorLineEdit->text();

                BaseConfigure::set_pile_vendor(ui->CPVendorLineEdit->text());
            }
            if (ui->CPModelLineEdit->text() != BaseConfigure::pile_model()) {
                if (ui->CPModelLineEdit->text().isEmpty()) {
                    return;
                }

                qDebug() << "[MAIN]-> Write Config charge Point Model:" << ui->CPModelLineEdit->text();

                BaseConfigure::set_pile_model(ui->CPModelLineEdit->text());
            }
            if (ui->QRPrefixLineEdit->text() != BaseConfigure::qrcode_prefix()) {
                if (ui->QRPrefixLineEdit->text().isEmpty()) {
                    return;
                }

                qDebug() << "[MAIN]-> Write Config QR-Prefix:" << ui->QRPrefixLineEdit->text();

                BaseConfigure::set_qrcode_prefix(ui->QRPrefixLineEdit->text());
            }
            if (ui->QRPostfixLineEdit->text() != BaseConfigure::qrcode_post()) {
                if (ui->QRPostfixLineEdit->text().isEmpty()) {
                    return;
                }

                qDebug() << "[MAIN]-> Write Config QR-Post:" << ui->QRPostfixLineEdit->text();

                BaseConfigure::set_qrcode_post(ui->QRPostfixLineEdit->text());
            }
            if (ui->NetAddrLineEdit->text() != BaseConfigure::net_ip()) {
                if (ui->NetAddrLineEdit->text().isEmpty()) {
                    return;
                }

                qDebug() << "[MAIN]-> Write Config Net-IP:" << ui->NetAddrLineEdit->text();

                BaseConfigure::set_net_ip(ui->NetAddrLineEdit->text());
            }
            if (ui->NetPortLineEdit->text().toInt() != BaseConfigure::net_port()) {
                if (ui->NetPortLineEdit->text().isEmpty()) {
                    return;
                }

                qDebug() << "[MAIN]-> Write Config Net-Port:" << ui->NetPortLineEdit->text();

                BaseConfigure::set_net_port(ui->NetPortLineEdit->text().toInt());
            }
            if (ui->NetProocolComboBox->currentText() != BaseConfigure::net_protocol()) {
                if (ui->NetProocolComboBox->currentText().isEmpty()) {
                    return;
                }

                qDebug() << "[MAIN]-> Write Config Net-Protocol:" << ui->NetProocolComboBox->currentText();

                BaseConfigure::set_set_protocol(ui->NetProocolComboBox->currentText());
            }
            break;
        case 0x01: //功能配置
            break;
        case 0x02: //系统配置
            break;
        case 0x03: //充电配置
            if (ui->APowerCtrLineEdit->text().toInt() != BaseConfigure::power_ctrl(kGunNumberA)) {
                if (ui->APowerCtrLineEdit->text().toInt() < 1) {
                    return;
                }
                if (ui->APowerCtrLineEdit->text().toInt() > 120) {
                    return;
                }

                qDebug() << "[MAIN]-> A.PowerCtr";

                memset(&(ControllerParserMain::con_feedback_power_ctrl[CON_PDUFORMAT_FEEDBACK_POWER_CTRL]), 0x00, sizeof(con_frame_info_t));
                BaseConfigure::set_power_ctrl(kGunNumberA, ui->APowerCtrLineEdit->text().toInt());
                ControllerSendMain::con_power_ctrl[kGunNumberA].gnu_no = CONGUNNOA;
                ControllerSendMain::con_power_ctrl[kGunNumberA].cmd_type = 1;
                ControllerSendMain::con_power_ctrl[kGunNumberA].ctrl_param = ui->APowerCtrLineEdit->text().toInt() * 10;
                ControllerSendMain::con_frame_info[CON_PDUFORMAT_POWER_CTRL].gunno = CONGUNNOA;
                ControllerSendMain::con_frame_info[CON_PDUFORMAT_POWER_CTRL].cycle = 250;
                ControllerSendMain::con_frame_info[CON_PDUFORMAT_POWER_CTRL].count = 0;
                ControllerSendMain::con_frame_info[CON_PDUFORMAT_POWER_CTRL].timeout = 5000;
                ControllerSendMain::con_frame_info[CON_PDUFORMAT_POWER_CTRL].time = ControllerSendMain::timestamp_ms();
                ControllerSendMain::con_frame_info[CON_PDUFORMAT_POWER_CTRL].pduformat = CON_PDUFORMAT_POWER_CTRL;
            }
            if (ui->BPowerCtrLineEdit->text().toInt() != BaseConfigure::power_ctrl(kGunNumberB)) {
                if (ui->BPowerCtrLineEdit->text().toInt() < 1) {
                    return;
                }
                if (ui->BPowerCtrLineEdit->text().toInt() > 120) {
                    return;
                }

                qDebug() << "[MAIN]-> B.PowerCtr";

                memset(&(ControllerParserMain::con_feedback_power_ctrl[CON_PDUFORMAT_FEEDBACK_POWER_CTRL]), 0x00, sizeof(con_frame_info_t));
                BaseConfigure::set_power_ctrl(kGunNumberB, ui->BPowerCtrLineEdit->text().toInt());
                ControllerSendMain::con_power_ctrl[kGunNumberB].gnu_no = CONGUNNOB;
                ControllerSendMain::con_power_ctrl[kGunNumberB].cmd_type = 1;
                ControllerSendMain::con_power_ctrl[kGunNumberB].ctrl_param = ui->BPowerCtrLineEdit->text().toInt() * 10;
                ControllerSendMain::con_frame_info[CON_PDUFORMAT_POWER_CTRL].gunno = CONGUNNOB;
                ControllerSendMain::con_frame_info[CON_PDUFORMAT_POWER_CTRL].cycle = 250;
                ControllerSendMain::con_frame_info[CON_PDUFORMAT_POWER_CTRL].count = 0;
                ControllerSendMain::con_frame_info[CON_PDUFORMAT_POWER_CTRL].timeout = 5000;
                ControllerSendMain::con_frame_info[CON_PDUFORMAT_POWER_CTRL].time = ControllerSendMain::timestamp_ms();
                ControllerSendMain::con_frame_info[CON_PDUFORMAT_POWER_CTRL].pduformat = CON_PDUFORMAT_POWER_CTRL;
            }
            break;
        case 0x04: //自检
            break;
        case 0x05: //升级
            break;
        default:
            break;
        }
    } else if ("GPCancelPB" == button_name) {
        hciMain_->set_action_config(false);
        ChangePage(HciMain::kHomePage);
    } else {
        //...
    }
}
